package com.tw;

/**
 * Created by admin on 16/06/14.
 */


public class Six {
    public static void main(String[] args) {
        int n = 3;
        generateDiamond(n);
    }

    private static void generateDiamond(int n) {
        generateIsoscelesTriangle(n, 0);
        generateInvertedIsoscelesTriangle(n - 1, 1);
    }

    private static void generateInvertedIsoscelesTriangle(int n, int verticalOffset) {
        int i, j;
        int rowStars = 1;
        for (i = 1; i < n; i++) {
            rowStars += 2;
        }
        for (i = 0; i < n; i++, rowStars -= 2) {
            for (j = 0; j < i + verticalOffset; j++) {
                System.out.print(" ");
            }
            for (j = 0; j < rowStars; j++) {
                System.out.printf("*");
            }
            System.out.println();
        }
    }

    private static void generateIsoscelesTriangle(int n, int verticalOffset) {
        int i, j;
        int rowStars = 1;
        for (i = n; i > 0; i--, rowStars += 2) {
            for (j = 0; j < i - 1 + verticalOffset; j++) {
                System.out.printf(" ");
            }
            for (j = 0; j < rowStars; j++) {
                System.out.print("*");
            }
            System.out.printf("\n");
        }
    }
}
